package com.sh.data.engine.web.webapi.controller.datadev;

import com.sh.data.engine.application.model.dto.base.PagerResponse;
import com.sh.data.engine.application.model.dto.datadev.*;
import com.sh.data.engine.application.model.request.datadev.*;
import com.sh.data.engine.application.service.datadev.OfflineDevApplicationService;
import com.sh.data.engine.common.enumDefinition.ProjectStatisticTypeEnum;
import com.sh.data.engine.domain.annotation.LogExecution;
import com.sh.data.engine.domain.annotation.ProjectStatisticExecution;
import com.sh.data.engine.domain.annotation.userlog.Business;
import com.sh.data.engine.domain.annotation.userlog.EngineOperation;
import com.sh.data.engine.web.webapi.controller.base.response.RestResponseEntity;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * @author: mengzheng.mhc
 * @date: 2024/7/10 9:41
 */
@Validated
@RestController
@RequestMapping("/offlineDev")
@Tag(name = "数据开发-离线作业开发", description = "离线开发相关API")
@Slf4j
public class OfflineDevController {

    @Autowired
    private OfflineDevApplicationService offlineDevApplicationService;

    @GetMapping("/node/listAll")
    @Operation(summary = "查询全部节点")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<List<OfflineDevNodeResponse>> listAllNode(
        @Parameter(description = "节点id,1-作业开发 2-工作流程 3-资源 4-函数", required = true) @RequestParam Long id) {
        var result = offlineDevApplicationService.listAllNodes(id);
        return RestResponseEntity.success(result);
    }

    @SneakyThrows
    @GetMapping("/getLineage")
    public RestResponseEntity<List<String>> getLineageBySQL(
        @RequestParam(required = false) Long nodeId,
        @RequestParam(required = false) Long taskFlowId) {
        var result = offlineDevApplicationService.getLineageBySQL(nodeId, taskFlowId);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/node/delete")
    @Operation(summary = "删除节点，支持所有节点类型")
    @ProjectStatisticExecution(type = ProjectStatisticTypeEnum.DEVELOP_TASK_OFFLINE)
    @LogExecution(operation = EngineOperation.DEL, business = Business.离线开发任务流节点)
//    @Log(
//        business = Business.离线开发任务流节点,
//        operation = Operation.DEL)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> deleteNode(
        @Parameter(description = "节点id", required = true) @RequestParam Long id,
        @Parameter(description = "工作流Id: 作用删除工作流里面的任务需要填写", required = false) @RequestParam(required = false)
        Long taskFlowId,
        @Parameter(description = "是否删除该工作流程的所有节点任务，只在删除工作流程时使用", schema = @Schema(defaultValue = "false"))
        @RequestParam(required = false, defaultValue = "false")
        Boolean includeChildTask) {
        var result = offlineDevApplicationService.deleteNode(id, taskFlowId, includeChildTask, false);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/node/restoreNode")
    @Operation(summary = "还原节点，支持所有节点类型,回收站-还原使用")
    @LogExecution(operation = EngineOperation.RESTORE, business = Business.离线开发任务流节点)
/*     @Log(
        business = Business.离线开发任务流节点,
        operation = Operation.RESTORE) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> restoreNode(
        @Parameter(description = "节点id", required = true) @RequestParam Long id) {
        var result = offlineDevApplicationService.restoreNode(id);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/node/editNodeName")
    @Operation(summary = "编辑节点名称")
    @LogExecution(operation = EngineOperation.UPDATE, business = Business.离线开发任务流节点)
/*     @Log(
        business = Business.离线开发任务流节点,
        operation = Operation.UPDATE) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> editNodeName(
        @Parameter(description = "节点id", required = true) @RequestParam Long id,
        @Parameter(description = "新节点名称", required = true) @RequestParam String name) {
        var result = offlineDevApplicationService.editNodeName(id, name);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/node/clearNode")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    @Operation(summary = "清空节点，支持所有节点类型,回收站-清空节点,清空单个节点")
    public RestResponseEntity<Boolean> clearNode(
        @Parameter(description = "节点id", required = true) @RequestParam Long id) {
        var result = offlineDevApplicationService.deleteNode(id, null, true, true);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/node/clearAllNode")
    @Operation(summary = "清空所有节点，支持所有节点类型,回收站-清空所有节点")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> clearAllNode() {
        var result = offlineDevApplicationService.clearAllNodes();
        return RestResponseEntity.success(result);
    }

    @GetMapping("/node/detail")
    @Operation(summary = "获取节点详情")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<OfflineDevNodeDetailResponse> getTaskDetail(
        @Parameter(description = "任务节点id", required = true) @RequestParam Long id) {
        var result = offlineDevApplicationService.getTaskDetail(id);
        return RestResponseEntity.success(result);
    }

    /**
     * 移动节点至其他目录
     *
     * @return
     */
    @PostMapping("/dir/change")
    @Operation(summary = "移动节点至其他目录")
    @LogExecution(operation = EngineOperation.REMOVE, business = Business.离线开发任务流节点)
/*     @Log(
        business = Business.离线开发任务流节点,
        operation = Operation.REMOVE) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> changeDir(@Valid OfflineDevDirChangeRequest request) {
        var result = offlineDevApplicationService.changeDir(request);
        return RestResponseEntity.success(result);
    }

    /**
     * 节点排序
     *
     * @param request
     * @return
     */
    @PostMapping("/dir/sort")
    @Operation(summary = "目录排序")
    @LogExecution(operation = EngineOperation.SORT, business = Business.离线开发任务流节点)
/*     @Log(
        business = Business.离线开发任务流节点,
        operation = Operation.SORT) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> sortDir(@Valid OfflineDevDirSortRequest request) {
        var result = offlineDevApplicationService.sortDir(request);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/dir/save")
    @Operation(summary = "保存目录")
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发目录)
//    @Log(
//        business = Business.离线开发目录,
//        operation = Operation.ADD_UPDATE)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> saveDir(@Valid OfflineDevDirSaveRequest request) {
        var result = offlineDevApplicationService.saveDir(request);
        return RestResponseEntity.success(result);
    }

    @GetMapping(value = "/dir/tree")
    @Operation(summary = "获取目录树")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<List<OfflineDevDirTreeResponse>> getDirTree(
        @Parameter(description = "节点id", required = true) @RequestParam Long id) {
        var result = offlineDevApplicationService.getDirTree(id);
        return RestResponseEntity.success(result);
    }

    @GetMapping(value = "/taskflow/node/tree")
    @Operation(summary = "节点树")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<List<OfflineDevNodeResponse>> getUntilNodeType(
        @Parameter(description = "节点类型：2数据集成，3数据开发", required = true) @RequestParam Integer nodeType) {
        var result = offlineDevApplicationService.getUntilNodeType(nodeType);
        return RestResponseEntity.success(result);
    }

    @SneakyThrows
    @PostMapping("/upload")
    @Operation(summary = "上传文件")
    @LogExecution(operation = EngineOperation.UPLOAD, business = Business.离线开发资源节点)
//    @Log(
//        business = Business.离线开发资源节点,
//        operation = Operation.UPLOAD)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<OfflineDevUploadResourceResponse> uploadResource(
        @RequestPart("file") MultipartFile file) {
        var result = offlineDevApplicationService.uploadResource(file);
        return RestResponseEntity.success(result);
    }

    @Operation(summary = "保存资源节点")
    @PostMapping("/resource/saveResource")
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发资源节点)
//    @Log(
//        business = Business.离线开发资源节点,
//        operation = Operation.ADD_UPDATE)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> saveResourceTask(
        @Valid OfflineDevTaskResourceSaveRequest request) {
        var result = offlineDevApplicationService.saveResourceTask(request);
        return RestResponseEntity.success(result);
    }

    @Operation(summary = "获取资源列表")
    @GetMapping("/resource/listResource")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<List<OfflineDevResourceResponse>> listResourceTask(
        @Parameter(description = "nodeId", required = true) @RequestParam Long nodeId) {
        var result = offlineDevApplicationService.listResourceTask(nodeId);
        return RestResponseEntity.success(result);
    }

    @Operation(summary = "删除资源")
    @PostMapping("/resource/dropResource")
    @LogExecution(operation = EngineOperation.DEL, business = Business.离线开发资源节点)
//    @Log(
//        business = Business.离线开发资源节点,
//        operation = Operation.DEL)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> dropResource(
        @Parameter(description = "节点id", required = true) @RequestParam Long nodeId,
        @Parameter(description = "文件名称", required = true) @RequestParam String name) {
        var result = offlineDevApplicationService.dropResource(nodeId, name);
        return RestResponseEntity.success(result);
    }

    @Operation(summary = "获取资源详情")
    @GetMapping("/resource/getResourceDetail")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<OfflineDevResourceResponse> getResourceDetail(
        @Parameter(description = "节点id", required = true) @RequestParam Long nodeId) {
        var result = offlineDevApplicationService.getResourceDetail(nodeId);
        return RestResponseEntity.success(result);
    }

    @Operation(summary = "创建任务")
    @PostMapping("/task/save")
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发任务)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
/*     @Log(
        business = Business.离线开发任务,
        operation = Operation.ADD_UPDATE) */
    public RestResponseEntity<Boolean> saveTask(
        @Valid @RequestBody OfflineDevTaskSaveRequest request) {
        var result = offlineDevApplicationService.saveTask(request);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/taskFlow/setScheduleStatus")
    @Operation(summary = "设置工作流状态")
    @LogExecution(operation = EngineOperation.PUBLISH, business = Business.离线开发工作流)
/*     @Log(
        business = Business.离线开发工作流,
        operation = Operation.PUBLISH) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> setTaskFlowScheduleStatus(
        @Parameter(description = "工作流节点id", required = true) @RequestParam Long taskFlowNodeId,
        @Parameter(description = "状态 0-发布(未冻结) 1-未发布(冻结)", required = true) @RequestParam Integer status) {
        var result = offlineDevApplicationService.setTaskFlowScheduleStatus(taskFlowNodeId, status);
        return RestResponseEntity.success(result);
    }

    @Operation(summary = "作业开发-保存任务")
    @PostMapping("/work/save")
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发工作流节点)
//    @Log(
//        business = Business.离线开发工作流节点,
//        operation = Operation.ADD_UPDATE)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    @ProjectStatisticExecution(type = ProjectStatisticTypeEnum.DEVELOP_TASK_OFFLINE)
    public RestResponseEntity<Boolean> saveWorkTask(
        @Valid @RequestBody OfflineDevTaskSaveRequest request) {
        var result = offlineDevApplicationService.saveWorkTask(request);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/task/lock")
    @Operation(summary = "锁定/解锁任务")
    @LogExecution(operation = EngineOperation.LOCK_OR_UNLOCK, business = Business.离线开发工作流)
/*     @Log(
        business = Business.离线开发工作流,
        operation = Operation.LOCK_OR_UNLOCK) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> lockTask(
        @Parameter(description = "节点id", required = true) @RequestParam Long id,
        @Parameter(description = "状态 0-发布(未冻结) 1-未发布(冻结)", required = true, schema = @Schema(allowableValues = {"0", "1"}))
        @RequestParam
        Integer status) {
        var result = offlineDevApplicationService.lockTask(id, status);
        return RestResponseEntity.success(result);
    }

    /**
     * 保存脚本内容
     *
     * @return
     */
    @PostMapping("/task/script/save")
    @Operation(summary = "保存任务脚本")
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发脚本任务)
/*     @Log(
        business = Business.离线开发脚本任务,
        operation = Operation.ADD_UPDATE) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> saveTaskScript(
        @Valid @RequestBody OfflineDevTaskScriptSaveRequest request) {
        var result = offlineDevApplicationService.saveTaskScript(request);
        return RestResponseEntity.success(result);
    }

    /**
     * 脚本导入
     *
     * @return
     */
    @PostMapping("/task/script/import")
    @Operation(summary = "脚本导入")
    @LogExecution(operation = EngineOperation.IMPORT, business = Business.离线开发脚本任务)
/*     @Log(
        business = Business.离线开发脚本任务,
        operation = Operation.IMPORT) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<String> importTaskScript(
        HttpServletRequest request, @RequestPart("file") MultipartFile file) {
        var result = offlineDevApplicationService.importTaskScript(file, request.getParameterMap());
        return RestResponseEntity.success(result);
    }

    /**
     * 获取节点的脚本内容
     *
     * @return
     */
    @GetMapping("/task/script/detail")
    @Operation(summary = "获取节点的脚本内容")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<OfflineDevTaskScriptDetailResponse> getTaskScript(
        @Parameter(description = "节点id", required = true) @RequestParam Long id) {
        var result = offlineDevApplicationService.getTaskScript(id);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/task/clone")
    @Operation(summary = "克隆etl任务")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> cloneTask(@Valid @RequestBody OfflineDevTaskCloneRequest request) {
        var result = offlineDevApplicationService.cloneTask(request);
        return RestResponseEntity.success(result);
    }

    @GetMapping("/task/operation/history")
    @Operation(summary = "获取操作记录")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<PagerResponse<OfflineDevOperationHistoryResponse>> getTaskOperationHistory(
        @Parameter(description = "任务id", required = true) @RequestParam Long nodeId,
        @Parameter(description = "用户名或操作内容") @RequestParam(required = false) String content,
        @Parameter(description = "第几页") @RequestParam(required = false, defaultValue = "1") Integer pageNum,
        @Parameter(description = "每页大小") @RequestParam(required = false, defaultValue = "10")
        Integer pageSize) {
        var result = offlineDevApplicationService.getTaskOperationHistory(nodeId, content, pageNum, pageSize);
        return RestResponseEntity.success(result);
    }

    /**
     * 获取表列表--编辑脚本时提示用
     *
     * @return
     */
    @GetMapping(value = "/task/table/list")
    @Operation(summary = "获取表列表--编辑脚本时提示用")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<OfflineDevTaskTableInfoResponse> taskTableList() {
        var result = offlineDevApplicationService.taskTableList();
        return RestResponseEntity.success(result);
    }

    /**
     * 创建任务流
     *
     * @param request
     * @return
     */
    @PostMapping("/taskFlow/save")
    @Operation(summary = "保存工作流")
    @ProjectStatisticExecution(type = ProjectStatisticTypeEnum.DEVELOP_TASK_OFFLINE)
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发工作流)
/*     @Log(
        business = Business.离线开发工作流,
        operation = Operation.ADD_UPDATE) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> saveTaskFlow(@Valid OfflineDevTaskFlowSaveRequest request) {
        var result = offlineDevApplicationService.saveTaskFlow(request);
        return RestResponseEntity.success(result);
    }

    /**
     * 任务流详情,显示画板
     */
    @GetMapping("/taskFlow/detail")
    @Operation(summary = "工作流详情")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<OfflineDevTaskFlowDetailResponse> getTaskFlowDetail(
        @Parameter(description = "节点id", required = true) @RequestParam Long id) {
        var result = offlineDevApplicationService.getTaskFlowDetail(id);
        return RestResponseEntity.success(result);
    }

    /**
     * 任务流保存子节点
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/taskFlow/node/save")
    @Operation(summary = "工作流保存子节点，拖任务组件到画布时使用")
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发工作流节点)
//    @Log(
//        business = Business.离线开发工作流节点,
//        operation = Operation.ADD_UPDATE)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<OfflineDevTaskFlowDetailResponse.Node> saveTaskFlowNode(
        @Valid OfflineDevTaskFlowNodeSaveRequest request) {
        var result = offlineDevApplicationService.saveTaskFlowNode(request);
        return RestResponseEntity.success(result);
    }

    /**
     * 保存任务流子节点关系
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/taskFlow/node/relation/save")
    @Operation(summary = "保存工作流子节点关系")
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发上下游依赖)
//    @Log(
//        business = Business.离线开发上下游依赖,
//        operation = Operation.ADD_UPDATE)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> saveTaskFlowNodeRelation(
        @Valid OfflineDevFlowSubTaskDependencySaveRequest request) {
        var result = offlineDevApplicationService.saveTaskFlowNodeRelation(request);
        return RestResponseEntity.success(result);
    }

    /**
     * 删除任务流子节点关系
     */
    @PostMapping(value = "/taskFlow/node/relation/delete")
    @Operation(summary = "删除任务流子节点关系")
    @LogExecution(operation = EngineOperation.DEL, business = Business.离线开发上下游依赖)
//    @Log(
//        business = Business.离线开发上下游依赖,
//        operation = Operation.DEL)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> deleteTaskFlowNodeRelation(
        @Valid OfflineDevFlowSubTaskDependencyDeleteRequest request) {
        var result = offlineDevApplicationService.deleteTaskFlowNodeRelation(request);
        return RestResponseEntity.success(result);
    }

    @GetMapping("/taskFlow/vNode/detail")
    @Operation(summary = "工作流获取虚节点详情")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<OfflineDevTaskFlowVNodeDetailResponse> getTaskFlowVNodeDetail(
        @Parameter(description = "任务id", required = true) @RequestParam Long nodeId) {
        var result = offlineDevApplicationService.getTaskFlowVNodeDetail(nodeId);
        return RestResponseEntity.success(result);
    }

    @GetMapping("/taskFlow/node/detail")
    @Operation(summary = "工作流获取正常节点详情")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<OfflineDevTaskPropertyResponse> getTaskFlowNodeDetail(
        @Parameter(description = "任务id", required = true) @RequestParam Long nodeId) {
        var result = offlineDevApplicationService.getTaskFlowNodeDetail(nodeId);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/taskFlow/vNode/config/save")
    @Operation(summary = "工作流保存虚节点配置")
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发任务流节点)
/*     @Log(
        business = Business.离线开发任务流节点,
        operation = Operation.ADD_UPDATE) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> saveTaskFlowVNodeConfig(
        @Parameter(description = "开始节点任务id", required = true) @RequestParam Long nodeId,
        @Parameter(description = "描述") @RequestParam(required = false, defaultValue = "") String remark) {
        var result = offlineDevApplicationService.saveTaskFlowVNodeConfig(nodeId, remark);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/taskFlow/vNode/config/saveSchedule")
    @Operation(summary = "工作流保存调度配置")
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发任务调度配置)
//    @Log(
//        business = Business.离线开发任务调度配置,
//        operation = Operation.ADD_UPDATE)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> saveTaskFlowSchedule(
        @Valid @RequestBody OfflineDevTaskFlowVNodeConfigSaveRequest request) {
        var result = offlineDevApplicationService.saveTaskFlowSchedule(request);
        return RestResponseEntity.success(result);
    }

    @GetMapping("/resource/tree")
    @Operation(summary = "获取资源列表")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<List<OfflineDevResourceListResponse>> getOfflineDevResourceList() {
        var result = offlineDevApplicationService.getOfflineDevResourceList();
        return RestResponseEntity.success(result);
    }

    @PostMapping("/function/save")
    @Operation(summary = "保存函数")
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发函数节点)
//    @Log(
//        business = Business.离线开发函数节点,
//        operation = Operation.ADD_UPDATE)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> saveFunctionTask(
        @Valid OfflineDevFunctionSaveRequest offlineDevFunctionSaveRequest) {
        var result = offlineDevApplicationService.saveFunctionTask(offlineDevFunctionSaveRequest);
        return RestResponseEntity.success(result);
    }

    @GetMapping("/function/detail")
    @Operation(summary = "获取函数详情")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<OfflineDevFunctionDetailResponse> getOfflineDevFunctionDetailResponse(
        Long nodeId) {
        var result = offlineDevApplicationService.getOfflineDevFunctionDetail(nodeId);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/taskFlow/node/config/save")
    @Operation(summary = "工作流保存节点配置")
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发工作流节点配置)
//    @Log(
//        business = Business.离线开发工作流节点配置,
//        operation = Operation.ADD_UPDATE)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> saveTaskFlowNodeConfig(
        @Valid @RequestBody OfflineDevTaskFlowNodeConfigSaveRequest request) {
        var result = offlineDevApplicationService.saveTaskFlowNodeConfig(request);
        return RestResponseEntity.success(result);
    }

    @GetMapping("/taskFlow/list")
    @Operation(summary = "获取工作流程列表")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<List<OfflineDevTaskFlowResponse>> getTaskFlowList() {
        var result = offlineDevApplicationService.getTaskFlowList();
        return RestResponseEntity.success(result);
    }

    @PostMapping("/node/saveCoord")
    @Operation(summary = "批量保存节点坐标")
    @LogExecution(operation = EngineOperation.ADD_UPDATE, business = Business.离线开发上下游依赖)
//    @Log(
//        business = Business.离线开发上下游依赖,
//        operation = Operation.ADD_UPDATE)
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> saveNodeCoord(
        @RequestBody OfflineDevSaveNodeCoordRequest request) {
        var result = offlineDevApplicationService.saveNodeCoord(request);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/task/stop")
    @Operation(summary = "停止任务")
    @LogExecution(operation = EngineOperation.STOP_TASK, business = Business.离线开发任务流节点)
/*     @Log(
        business = Business.离线开发任务流节点,
        operation = Operation.STOP_TASK) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Boolean> taskStop(
        @Parameter(description = "任务id", required = true) @RequestParam("jobId") Long jobId) {
        var result = offlineDevApplicationService.stopJob(jobId);
        return RestResponseEntity.success(result);
    }

    @GetMapping("/task/log")
    @Operation(summary = "任务日志")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<OfflineDevTaskLogResponse> taskLog(
        @Parameter(description = "任务id", required = true) @RequestParam("jobId") Long jobId,
        @Parameter(description = "偏移量", required = true) @RequestParam("offset") Integer offset,
        @Parameter(description = "") @RequestParam(value = "rsHasShow", required = false) String rsHasShow) {
        var result = offlineDevApplicationService.taskLog(jobId, offset, rsHasShow);
        return RestResponseEntity.success(result);
    }

    @PostMapping("/task/sql/start")
    @Operation(summary = "启动SQL任务")
    @LogExecution(operation = EngineOperation.START_TASK, business = Business.离线开发任务流节点)
/*     @Log(
        business = Business.离线开发任务流节点,
        operation = Operation.START_TASK) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Long> taskStart(@RequestBody OfflineDevTaskRunRequest request) {
        var result = offlineDevApplicationService.taskStart(request);
        return RestResponseEntity.success(result);
    }

    @GetMapping("/task/result/download")
    @Operation(summary = "任务执行结果下载")
    @LogExecution(operation = EngineOperation.DOWNLOAD, business = Business.离线开发计算结果)
/*     @Log(
        business = Business.离线开发计算结果,
        operation = Operation.DOWNLOAD) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public void downloadTaskResult(
        @Parameter(description = "任务id", required = true) @RequestParam("jobId") Long jobId,
        @Parameter(description = "结果", required = true) @RequestParam("result") String result,
        @Parameter(hidden = true) HttpServletResponse response) {
        offlineDevApplicationService.downloadTaskResult(jobId, result, response);
    }

    @PostMapping("/flow/task/start")
    @Operation(summary = "启动任务")
    @LogExecution(operation = EngineOperation.START_TASK, business = Business.离线开发工作流)
/*     @Log(
        business = Business.离线开发工作流,
        operation = Operation.START_TASK) */
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 1)
    public RestResponseEntity<Long> flowTaskStart(
        @Parameter(description = "node id ", required = true) @RequestParam("nodeId") Long nodeId) {
        var result = offlineDevApplicationService.flowTaskStart(nodeId);
        return RestResponseEntity.success(result);
    }

    @GetMapping("/taskFlow/status")
    @Operation(summary = "获取工作流各节点的运行状态")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<List<OfflineDevTaskFlowStatusResponse>> getTaskFlowStatus(
        @Parameter(description = "任务id", required = true) @RequestParam Long jobId) {
        var result = offlineDevApplicationService.getTaskFlowStatus(jobId);
        return RestResponseEntity.success(result);
    }

    // 根据数据源类型返回组建列表

    @GetMapping("/taskflow/toolList")
    @Operation(summary = "根据底层存储更换组建列表")
//    @AuthorityAnnotation(menuId = MenuEnumNew.ZYKF, readWriteStatus = 0)
    public RestResponseEntity<OfflineDevToolsResponse> getDevToolList() {
        var result = offlineDevApplicationService.getDevToolList();
        return RestResponseEntity.success(result);
    }
}
